<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
        *{
            margin: 0;padding: 0;box-sizing: border-box;
        }
        .container{
            width: 400px;
            min-height: 300px; 
            margin: 100px auto;
        }
        .show{
            width: 100%;
            height: 300px;
            background:#aef;
        }

    </style>
</head>
<body>
    <div id="root">
        
    </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class TSB extends React.Component {
            //声明状态
            state = {
                r: 0,
                g: 0,
                b: 0
            }
            render(){
                let {r, g, b} = this.state;
                return <div className="container">
                            <div className="show" style={{background: `rgb(${r},${g},${b})`}}>

                            </div>
                            <div className="control">
                                R: <input type="range" min="0" max="255" value={r}  name="r"  onChange={this.saveData}/> {r}<br />
                                G: <input type="range" min="0" max="255" value={g}  name="g"  onChange={this.saveData}/> {g}<br />
                                B: <input type="range" min="0" max="255" value={b}  name="b"  onChange={this.saveData}/> {b}<br />
                            </div>
                        </div>
            }
            
            saveData = e => {
                //获取组件对应的 state 属性
                let key = e.target.name;
                this.setState({
                    [key]: e.target.value
                })
            }
         }

        //渲染
        ReactDOM.render(<TSB />, document.querySelector('#root'));
    </script>
</body>
</html>